<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>积分</title>
    <link rel="stylesheet" href="/dor/layui/layui.css" />
    <!--<link rel="stylesheet" href="/dor/layui/layer.css" />-->
    <script src="/dor/js/jquery-3.2.1.js"></script>
    <script src="/dor/layui/layui.all.js"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/css/search.css}"/>
</head>
<body>
<!--轮播图片-->
<div class="layui-carousel" id="test1">
    <div carousel-item="">
        <div><img src="image/lun.jpg" width="100%" height="100%"/></div>
        <div><img src="image/lun2.jpg" width="100%" height="100%"/></div>
        <div><img src="image/13.jpg" width="100%" height="120%"/></div>
    </div>
</div>
<script>
    layui.use('carousel', function () {
        var carousel = layui.carousel;
        //建造实例
        carousel.render({
            elem: '#test1'
            , width: '100%' //设置容器宽度
            , arrow: 'none' //始终显示箭头
            , width: '1080px'
            , height: '150px'
            //,anim: 'updown' //切换动画方式
        });
    });
</script>
<fieldset class="layui-elem-field layui-field-title" >
    <legend><span class="" style="font-size: 14px">
        <a href="/dor/indexdemo">首页<span class="layui-box">&gt;</span></a>
  <span>查寝情况<span class="layui-box">&gt;</span></span>
  <span>积分系统<span class="layui-box">&gt;</span></span>
</span>
    </legend>
</fieldset>
<div style="position:relative; left: 10px">
<button class="layui-btn layui-btn-normal" id="openInit">初始化积分系统</button>
</div>
<div style="display: flex;position: relative;top: 5px" class="demoTable">
    <label class="layui-form-label">寝室号</label>
    <form id="frm" method="get">
        <div style="display: flex" >
            <div id="sss">
                <select  id="build"  class="search_select"></select>
                <select  id="room" class="search_select"></select>
                <input id="r_id" hidden="hidden" name="rid"/>
            </div>
            <button class="layui-btn" data-type="reload" id="ss">搜索</button>
        </div>
    </form>
    <button class="layui-btn layui-btn-normal" id="jfgz" style="position: relative;left: 500px">积分规则</button>
</div>

<table id="LAY_table_user" lay-filter="demo">
</table>

<script>
    var rid
    layui.use('table', function() {
        var table = layui.table;
        //方法级渲染
        table.render({
            elem: '#LAY_table_user'
            , url: '/dor/jifenmain'
            , cols: [[
                {checkbox: true, fixed: true}
                /*, {field: 'id', title: 'ID', width: 120, sort: true, fixed: true}*/
                , {field: 'fang', title: '寝室号', width: 180, sort: true}
                , {field: 'score', title: '积分', width: 180, sort: true}
               /* , {field: '', title: '操作', width: 135, toolbar: '#barDemo'}*/
            ]]
            , id: 'LAY_table_user'
            , page: true
            , height: 0
        });

        var $ = layui.$, active = {
            reload: function(){
                var query2 = $('#r_id').val()
                table.reload('LAY_table_user', {
                    where: {
                        rid : query2
                    }
                });
            }
        };

        $('#ss').on('click', function(e){
            e.preventDefault()
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    })


</script>
<script>
    /*<![CDATA[*/
    $("#openInit").on('click', function () {
        layer.open({
            title: '初始化积分系统'
            ,content: '<div>年份：<select class="search_select" name="years" id="years"><option value="1" id="firstYear"> </option><option value="2" id="secondYear"> </option></select>'
            +'学期：<select class="search_select" name="terms" id="terms"><option value="1">上半年</option><option value="2">下半年</option></select>'
            +'<button class="layui-btn layui-btn-normal" id="initBtn">确定初始化</button></div>'
            ,btn:[]
        });

        var date = new Date()
        var years = date.getYear()+1900;
        $("#firstYear").attr('value', years)
        $("#firstYear").html(years)
        $("#secondYear").attr('value', years+1)
        $("#secondYear").html(years+1)
        $("#initBtn").on('click', function () {
            var years = $("#years").val()
            var terms = $("#terms").val()
//        console.log(years+terms)
            $.get('/dor/initJF/'+years+"/"+terms, function (data) {
                console.log(data)
                if(data==='Already'){
                    layer.msg('已经初始化过')
                }else{
                    layer.msg('初始化成功,一共初始化 '+data+' 个寝室')
                }

            })
        })
    });

    //删除上一学年的积分；
    var date = new Date();
    var year = date.getYear()+1900;
    var month = date.getMonth()+1;
    var term;
    if (month >= 9 && month <= 12)
    {
        term = 1
    }else if (month < 9){
        year = year - 1;
        month = 2;
    }
    $.get('/dor/jfDel/'+year+"/"+term, function (data) {
        console.log(data)

    })


    //积分规则
    $("#jfgz").on('click', function () {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.open({
                title: '积分规则'
                ,content: '<sapn>根据寝室检查来加减积分</sapn>' +
                '<table class="layui-table"><tr><td>卫生</td><td>得分</td></tr>' +
                '<tr><td>优</td><td>+2</td></tr>' +
                '<tr><td>良</td><td>+1</td></tr>' +
                '<tr><td>中</td><td>+0</td></tr>' +
                '<tr><td>差</td><td>-1</td></tr>' +
                '<tr><td>违规</td><td>-2</td></tr>' +
                '<tr><td>差</td><td>-1</td></tr></table>'
                ,closeBtn: 0
                ,maxWidth: 400
            });

        });
    })


    /*]]>*/
</script>


<script>
    //寝室号的选择 拼接
    /*<![CDATA[*/
    $.get('/dor/build', function (data) {
//        console.log(data)
        buildList = '<option selected="selected">选择楼栋</option>'
        data.forEach(function (value) {
//            console.log(value)
            buildList+='<option>'+value.build_id+'</option>'
        })
        /*  console.log(buildList)*/
        $("#build").html(buildList)
    })

    $("#build").on('click', function () {
        var build = $("#build").val()
        console.log('0'+build)
        $.get('/dor/rooms/'+build, function (data) {
//        console.log(data)
            buildList = '<option>选择寝室</option>'
            data.forEach(function (value) {
//            console.log(value)
                buildList+='<option value="'+value.id+'">'+value.room_id+'</option>'
            })
//            console.log(buildList)
            $("#room").html(buildList)
        })
    })


    /* 寝室编号的拼接*/
    var build;
    var room;
    $('#build').change(function () {
        build = $('#build').val();
        if (build != undefined && room != undefined) {
            $('#r_id').val(room)
        }
    })
    $('#room').change(function () {
        room = $('#room').val()
        if (build != undefined && room != undefined) {
            $('#r_id').val(room)
            console.log(room)
        }
    })
    /*]]>*/
</script>
</body>
</html>